/*
 * QQ相关功能
 * @author:杨红伟
 * @date：2017.09.27
 * @link http://docs.apicloud.com/Client-API/Open-SDK/qq
 */
(function(window){
	"use strict";
	var nuiQq = function(){
		this._init();
	};

	var showToast = function(msg, duration, location) {
		var msg = msg ? msg : '错误';
		var duration = duration ? duration : '2000';
		var location = location ? location : 'bootom';
		api.toast({
			msg: msg,
			duration: duration,
			location: location
		});
	}

	nuiQq.prototype = {

		//初始化
		_init:function () {
			if(typeof(api) == 'undefined'){
				console.log('该插件必须在APICloud中运行');
			}else{
				this.qq = api.require('qq');
				var qq = this.qq;
				qq.installed(function(ret, err) {
				    if (ret.status) {
				        //api.alert({ msg: "安装了QQ可以分享" });
				    } else {
				        api.alert({ msg: "没有安装QQ不能分享" });
				    }
				});
			}
		},


		//分享文本
		shareText : function(Text){
			var qq = this.qq;
			qq.shareText({
				text: Text
			},function (ret,err) {
				if(ret.status){
					showToast('分享成功！',2,'bottom');
				}
			});
		},

		//分享图片（本地）到好友
		shareImage : function(Text,Title,Description,ImgPath){
			var qq = this.qq;
			qq.shareImage({
				text: Text,
				title: Title,
		    description: Description,
		    imgPath: ImgPath
			},function (ret,err) {
				if(ret.status){
					showToast('分享成功！',2,'bottom');
				}
			});
		},

		//分享新闻到空间/好友
		// Type 分享内容到好友或空间，取值范围：QZone、QFriend
		shareNews : function(Url,Title,Description,ImgUrl,Type){
			var qq = this.qq;
			qq.shareNews({
				url: Url,
		    title: Title,
		    description: Description,
		    imgUrl: ImgUrl,
				type: Type
			},function (ret,err) {
				if(ret.status){
					showToast('分享成功！',2,'bottom');
				}
			});
		},

		//分享音乐到空间/好友
		shareMusic : function(Url,Title,Description,ImgUrl,Type){
			var qq = this.qq;
			qq.shareMusic({
				url: Url,
		    title: Title,
		    description: Description,
		    imgUrl: ImgUrl,
				type: Type
			},function (ret,err) {
				if(ret.status){
					showToast('分享成功！',2,'bottom');
				}
			});
		},

		//分享视频到空间/好友
		shareVideo : function(Url,Title,Description,ImgUrl,Type){
			var qq = this.qq;
			qq.shareVideo({
				url: Url,
		    title: Title,
		    description: Description,
		    imgUrl: ImgUrl,
				type: Type
			},function (ret,err) {
				if(ret.status){
					showToast('分享成功！',2,'bottom');
				}
			});
		},



	};

	window.nuiQq = nuiQq;
})(window);
